<template>
    <div class="root">
        <div class="back"></div>
        <router-link to="/login" class="back-text">返回登录页</router-link>

        <div class="contain">
            <div class="title">用户注册</div>
            <div style="height: 20px;"></div>
            <div class="form-item">
                <div class="f-title">昵称</div>
                <input class="f-input" v-model="formInfo.nickname" type="text" placeholder="请输入昵称">
            </div>
            <div class="form-item">
                <div class="f-title">用户名</div>
                <input class="f-input" v-model="formInfo.username" type="text" placeholder="请输入用户名">
            </div>
            <div class="form-item">
                <div class="f-title">邮箱</div>
                <input class="f-input" v-model="formInfo.email" type="text" placeholder="请输入邮箱，用于找回密码">
            </div>
            <div class="form-item">
                <div class="f-title">电话号</div>
                <input class="f-input" v-model="formInfo.phoneNumber" type="text" placeholder="请输入电话号">
            </div>
            <div class="form-item">
                <div class="f-title">密码</div>
                <input class="f-input" v-model="formInfo.password" type="password" placeholder="请输入密码">
            </div>
            <div class="form-item">
                <div class="f-title">确认密码</div>
                <input class="f-input" v-model="formInfo.confirmPassword" type="password" placeholder="请再次输入密码">
            </div>
            <div class="form-item">
                <div class="f-title">地址</div>
                <textarea rows="4" class="f-textarea"></textarea>
            </div>
            <input class="base-button" type="button" value="注册" @click="register">
        </div>
    </div>
</template>

<script setup>
import {ref} from 'vue'
import UserApi from '@/api/user.js'
import router from "@/router/index.js";
import { ElMessage } from 'element-plus'
let formInfo = ref({
    username: '',
    password: '',
    confirmPassword: '',
    nickname: '',
    email: '',
    phoneNumber: '',
    address: '',
    permission: '2'
})

function register() {
    UserApi.register(formInfo.value).then(res => {
        if(res.data.code === 20000){
            ElMessage.success(res.data.msg)
            router.push('/login')
        }else{
            ElMessage.error(res.data.msg)
        }
    })
}
</script>

<style scoped lang="scss">
.root {
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    background-color: #f6f6f6;

    .back {
        position: absolute;
        top: 0;
        left: 0;
        width: 0;
        height: 0;
        border-top: 130px solid #86a0ae;
        border-right: 130px solid transparent;
    }
    .back-text {
        position: absolute;
        top: 40px;
        left: 10px;
        transform: rotate(-45deg);
        color: #f6f6f6;
        font-weight: bold;
        text-decoration: none;
        cursor: pointer;
    }

    .contain {
        width: 600px;
        height: fit-content;
        //background-color: #f5f5f5;
        margin: 60px auto 0;
        display: flex;
        flex-direction: column;
        align-items: center;

        .form-item {
            display: flex;
            margin-bottom: 10px;
            align-items: center;
            justify-content: center;

            .f-title {
                width: 80px;
                font-size: 18px;
                color: #333;
            }

            .f-input {
                width: 300px;
                height: 35px;
                margin: 8px 0;
                background-color: #ffffff;
                outline: none;
                border: none;
                border-radius: 5px;
                padding: 0 10px;
                box-sizing: border-box;
                font-size: 16px;
                color: #514d3f;
                font-weight: bold;

                &::placeholder {
                    color: #cccccc;
                }
            }

            .f-textarea {
                width: 300px;
                resize: none;
                background-color: #ffffff;
                outline: none;
                border: none;
                border-radius: 5px;
                padding: 0 10px;
                box-sizing: border-box;
                font-size: 16px;
                color: #514d3f;
                font-weight: bold;
            }
        }

        .title {
            font-size: 30px;
            font-weight: 600;
            text-align: center;
            margin-bottom: 20px;
            color: #333;
        }

        .base-button {
            width: 400px;
            height: 35px;
            margin: 13px 0;
            background-color: #667c77;
            color: #ffffff;
            border: none;
            border-radius: 5px;
            font-size: 16px;

            &:hover {
                background-color: #778e89;
                color: #e7e2e2;
            }

            &:active {
                background-color: #526460;
                color: #d3cece;
            }

            transition: all 0.2s;
            cursor: pointer;
        }
    }
}
</style>
